package com.xmtlxx.system.mapper;

import com.xmtlxx.common.annotation.DataColumn;
import com.xmtlxx.common.annotation.DataPermission;
import com.xmtlxx.common.core.domain.entity.SysUser;
import com.xmtlxx.common.core.mapper.BaseMapperPlus;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 用户表 数据层
 *
 * @author xmtlxx
 */
public interface SysUserMapper extends BaseMapperPlus<SysUserMapper, SysUser, SysUser> {

    @DataPermission({
        @DataColumn(key = "tenantName", value = "u.create_by"),
        @DataColumn(key = "deptName", value = "d.dept_id"),
        @DataColumn(key = "userName", value = "u.user_id")
    })
    Page<SysUser> selectPageUserList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);

    /**
     * 根据条件分页查询用户列表
     *
     * @param user 用户信息
     * @return 用户信息集合信息
     */
    @DataPermission({
        @DataColumn(key = "tenantName", value = "u.create_by"),
        @DataColumn(key = "deptName", value = "d.dept_id"),
        @DataColumn(key = "userName", value = "u.user_id")
    })
    List<SysUser> selectUserList(SysUser user);

    List<SysUser> selectUsers(SysUser user);

    List<SysUser> selectUserAll(@Param("roleKey") String roleKey,@Param("deptId") Long deptId);

    List<SysUser> selectUserByCar(@Param("roleKey") String roleKey,@Param("deptId") Long deptId);

    /**
     * 根据条件分页查询已配用户角色列表
     *
     * @param user 用户信息
     * @return 用户信息集合信息
     */
    @DataPermission({
        @DataColumn(key = "tenantName", value = "u.create_by"),
        @DataColumn(key = "deptName", value = "d.dept_id"),
        @DataColumn(key = "userName", value = "u.user_id")
    })
    Page<SysUser> selectAllocatedList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);

    /**
     * 根据条件分页查询未分配用户角色列表
     *
     * @param user 用户信息
     * @return 用户信息集合信息
     */
    @DataPermission({
        @DataColumn(key = "tenantName", value = "u.create_by"),
        @DataColumn(key = "deptName", value = "d.dept_id"),
        @DataColumn(key = "userName", value = "u.user_id")
    })
    Page<SysUser> selectUnallocatedList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);

    /**
     * 通过用户名查询用户
     *
     * @param userName 用户名
     * @return 用户对象信息
     */
    SysUser selectUserByUserName(String userName);

    /**
     * 通过用户ID查询用户
     *
     * @param userId 用户ID
     * @return 用户对象信息
     */
    SysUser selectUserById(Long userId);

    SysUser selectUserId(@Param("user") SysUser user);

    /**
     * 通过租户ID查询租户管理员
     *
     * @param tenantId 租户ID
     * @return 用户对象信息
     */
    SysUser getTenantAdminUser(Long tenantId);

    /**
     * 首页用户数量统计
     * @param userType
     * @return
     */
    @DataPermission({
        @DataColumn(key = "tenantName", value = "u.create_by"),
        @DataColumn(key = "deptName", value = "d.dept_id"),
        @DataColumn(key = "userName", value = "u.user_id")
    })
    Map<String,Object> selectIndexCounts(String userType);

    /**
     * 获取用户ID集合
     * @param deptid
     * @param roleid
     * @return
     */
    Map<String,Object> getUserIds( @Param("deptId")Long deptId, @Param("roleId")Long roleId);

    String getUserPhoneNumber(@Param("userName") String userName);

}
